package com.hod.client.reports;

import java.util.ArrayList;

import com.google.gwt.gears.client.database.DatabaseException;
import com.google.gwt.gears.client.database.ResultSet;
import com.google.gwt.user.client.Window;
import com.google.gwt.visualization.client.AbstractDataTable;
import com.google.gwt.visualization.client.DataTable;
import com.google.gwt.visualization.client.AbstractDataTable.ColumnType;
import com.hod.client.backend.orm.client.GearsDataObject;
import com.hod.client.checkout.CheckOut;
import com.hod.client.client.Client;
import com.hod.client.client.ClientCRUD;
import com.hod.client.client.ClientRecordset;
import com.hod.client.lodging.Lodging;
import com.hod.client.lodging.LodgingCRUD;
import com.hod.client.lodging.LodgingRecordset;

public class CheckOutDataTableView extends DataTableView {

	@Override
	public AbstractDataTable createTableData(ArrayList<GearsDataObject> rs) {
		// TODO Auto-generated method stub
		DataTable data = DataTable.create();
	    data.addColumn(ColumnType.STRING , "Client");
	    data.addColumn(ColumnType.DATE , "CheckIn");	    
	    data.addColumn(ColumnType.DATE , "CheckOut");
	    data.addColumn(ColumnType.STRING , "Charges");
	    data.addColumn(ColumnType.NUMBER , "Days");
	    data.addColumn(ColumnType.STRING, "RoomCharges");
	    data.addColumn(ColumnType.STRING , "Beck");
	    int cantrows = 0;
		for (GearsDataObject object :rs){
				CheckOut checkOut = (CheckOut)object;
				data.addRow();
				Client client = ClientRecordset.getClient(checkOut.getIdClient());
			    data.setValue(cantrows, 0, client.getSurname()+", "+ client.getName());
			    Lodging lodging = LodgingRecordset.getLodging(checkOut.getIdLodging());
			    data.setValue(cantrows, 1, lodging.getCheckIn());
			    data.setValue(cantrows, 2, lodging.getCheckOut());
			    data.setValue(cantrows, 3, checkOut.getTotalCharges());
			    data.setValue(cantrows, 4, 0);
			    data.setValue(cantrows, 5, checkOut.getTotalRoomCharges());
			    data.setValue(cantrows, 6, checkOut.getBeck());
			    ++cantrows;
		}
	    return data ;
	}

}
